package com.anxin.registerManagement.service;

import cn.hutool.core.util.ObjectUtil;
import com.anxin.registerManagement.bean.dto.ProfessionDto;
import com.anxin.registerManagement.bean.jo.ProfessionSearchJo;
import com.anxin.registerManagement.bean.persist.Profession;
import com.anxin.registerManagement.mapper.ProfessionMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author 叶前呈
 * @date 2022/1/28 16:42
 */
@Service
public class ProfessionService {

    private static Logger logger = LoggerFactory.getLogger(ProfessionService.class);

    @Autowired
    ProfessionMapper professionMapper;

    /**
     * 查询专业
     */
    public PageInfo<ProfessionDto> getProfessionList(ProfessionSearchJo professionSearchJo) {
        if (!ObjectUtil.isEmpty(professionSearchJo.getPageNum()) && !ObjectUtil.isEmpty(professionSearchJo.getPageSize())) {
            PageHelper.startPage(professionSearchJo.getPageNum(), professionSearchJo.getPageSize());
        }
        List<ProfessionDto> professionDtoList = professionMapper.getProfessionList(professionSearchJo);
        return new PageInfo<>(professionDtoList);
    }

    /**
     * 添加专业
     */
    public void addProfession(Profession profession) {
        // TODO:判断专业名称是否存在，学院是否存在，设立年份自动计算
        professionMapper.insert(profession);
        logger.info("添加专业：{}，成功", profession);
    }

    /**
     * 修改专业
     */
    public void updateProfession(Profession profession) {
        // TODO:这里只需要判断名称、学院是否存在，设立年份不需要进行，其次如果超过9月1日，只能修改明年数据，不超过只能修改今年数据
        professionMapper.updateById(profession);
        logger.info("修改专业：{}，成功", profession);

    }

    /**
     * 删除专业
     */
    public void deleteProfession(int id) {
        // TODO:这里删除专业，需要关联班级，学生，因此需要进一步判断
        professionMapper.deleteById(id);
        logger.info("删除id：{} 专业，成功", id);
    }


    /**
     * 获取所有专业
     */
    public List<Profession> getAllProfession() {
        return professionMapper.selectList(null);
    }

}
